package com.cqrt.vo;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.hustcad.plm.pdm.container.model.vo.search.ProjectEntityVO;
import com.hustcad.plm.rpm.model.dto.active.PlusTaskDTO;
import com.hustcad.plm.rpm.model.vo.job.TyppmJobVO;
import lombok.Data;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@Data
public class RTProjectRelationVO {

    private List<PlusTaskDTO> curJobs;
    @JsonSerialize(using = ProjectJobMapSerializer.class)
    private Map<ProjectEntityVO, List<PlusTaskDTO>> jobMap;
    private Long total;

    public static class ProjectJobMapSerializer extends JsonSerializer<Map<ProjectEntityVO, List<TyppmJobVO>>> {
        @Override
        public void serialize(Map<ProjectEntityVO, List<TyppmJobVO>> map,
                              JsonGenerator gen,
                              SerializerProvider serializers) throws IOException {
            // 序列化逻辑和之前相同
            gen.writeStartArray();
            for (Map.Entry<ProjectEntityVO, List<TyppmJobVO>> entry : map.entrySet()) {
                gen.writeStartObject();
                gen.writeObjectField("project", entry.getKey());
                gen.writeObjectField("jobs", entry.getValue());
                gen.writeEndObject();
            }
            gen.writeEndArray();
        }
    }

}
